/*************************************************************************
> File Name: mold.cpp
> Author: icebear
> Mail: 3322366195@qq.com
> Created Time: 2023-08-02 09:26:35
> Description:
************************************************************************/

#include <iostream>

using namespace std;

class Solution
{
public:
    int reverse(int x)
    {
        int res = 0;
        int last = 0;
        while (x != 0)
        {
            if (res < -214748364 || res > 214748364)
            {
                return 0;
            }
            // 每次取末尾数字
            int tmp = x % 10;
            last = res;
            res = res * 10 + tmp;
            // 判断整数溢出
            x /= 10;
        }
        return res;
    }
};
int main(int argc, char const *argv[])
{
    Solution solution;
    int x = 1534236469;
    int result = solution.reverse(x);
    cout << result << endl;

    x = -2147483412;
    result = solution.reverse(x);
    cout << result << endl;
    return 0;
}
